<template>
  <footer class="footer-container">
    <!-- 备案信息 -->
    <div class="footer-nav d-none d-md-flex">
      <div class="footer-nav-start">
        <div class="records">
          <span>Copyright © 2022 知识渔 · </span>
          <a href="javascript:;">豫ICP备12009440号</a>
        </div>
        <div
          class="footer_nav_start_item"
          v-for="(item, index) in renderContent"
          :key="index"
        >
          <span class="footer_item">
            {{ item.title }}
          </span>
        </div>
      </div>
      <div class="footer-nav-end">
        <p>
          耗时
          {{ handlerTime }}
          秒
        </p>
      </div>
    </div>
    <!-- 移动端底部栏 -->
    <div class="webapp_footer d-md-none">
      <div class="webapp_footer_start">
        <div
          class="webapp_footer_item"
          @click="toPages(item.url)"
          v-for="(item, index) in sidebar_start"
          :key="index"
        >
          <i :class="`iconfont ${item.icon}`"> </i>
          <span>{{ item.title }}</span>
        </div>
      </div>
      <div class="webapp_footer_center">
        <button class="el-icon-plus"></button>
      </div>
      <div class="webapp_footer_end">
        <div
          class="webapp_footer_item"
          @click="toPages(item.url)"
          v-for="(item, index) in sidebar_end"
          :key="index"
        >
          <i :class="`iconfont ${item.icon}`"> </i>
          <span>{{ item.title }}</span>
        </div>
      </div>
    </div>
  </footer>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "MyFooter",
  props: ["startTime"],
  computed: {
    ...mapState("user", ["userInfo"]),
    handlerTime() {
      if (!this.d1) return 0;
      let sec = (this.d1 - this.d2) / 1000;
      return sec.toFixed(4).replace(/0*$/, "");
    },
  },
  data() {
    return {
      // 移动端底部栏
      sidebar_start: [
        {
          title: "Q群",
          icon: "icon-tencentqq",
          url: `/sundry/flock`,
        },
      ],
      sidebar_end: [
        {
          title: "我的",
          icon: "icon-yonghu",
          url: `/center/:id`,
        },
      ],
      // 开始时间，结束时间
      d1: 0,
      d2: window.performance?.timing.domLoading,
      // 数据列表
      renderContent: [
        {
          title: "隐私权声明",
          href: "",
        },
        {
          title: "用户规范",
          href: "",
        },
        {
          title: "版权声明",
          href: "",
        },
        {
          title: "素材使用协议",
          href: "",
        },
        {
          title: "联系我们",
          href: "",
        },
        {
          title: "QQ群",
          href: "",
        },
        {
          title: "哔哩哔哩",
          href: "",
        },
        {
          title: "公共",
          href: "",
        },
        {
          title: "关于",
          href: "",
        },
      ],
    };
  },
  methods: {
    toPages(url) {
      if (/\/:id/.test(url)) {
        if (!this.userInfo.id) {
          // 代表登录或注册成功后会跳转到我的个人页
          this.$router.push(`/user/mobileLogin?center=true`);
        } else {
          this.$router.push(`/center/${this.userInfo.id}`);
        }
      } else {
        this.$router.push(url);
      }
    },
  },
  mounted() {
    this.d1 = window.performance?.timing.domContentLoadedEventEnd;
    let timer = setInterval(() => {
      if (!this.d1) {
        this.d1 = window.performance?.timing.domContentLoadedEventEnd;
      } else {
        clearInterval(timer);
      }
    }, 500);
  },
};
</script>

<style lang="less" scoped>
@media screen and (max-width: 1260px) {
  .footer-container {
    .footer_nav_start_item {
      &:nth-of-type(10) {
        display: none;
      }
      &:nth-of-type(9) {
        display: none;
      }
      &:nth-of-type(8) {
        display: none;
      }
      &:nth-of-type(7) {
        display: none;
      }
      &:nth-of-type(6) {
        display: none;
      }
    }
  }
}

@media screen and (max-width: 996px) {
  .footer-container {
    .footer_nav_start_item {
      &:nth-of-type(5) {
        display: none;
      }
      &:nth-of-type(4) {
        display: none;
      }
      &:nth-of-type(3) {
        display: none;
      }
    }
  }
}

.footer-container {
  background: #222;
  color: #999;
  font-size: 14px;
  padding: 0 100px;
  .webapp_footer {
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 2200;
    width: 100vw;
    height: 56px;
    background: #fff;
    box-shadow: 0 -1px 3px 0 rgb(26 26 26 / 10%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    .webapp_footer_item {
      display: flex;
      flex-direction: column;
    }
    .webapp_footer_center {
      button {
        font-weight: 700;
        font-size: 18px;
        color: #fff;
        height: 30px;
        display: block;
        text-align: center;
        border-radius: 3px;
        width: 40px;
        line-height: 26px;
        border-radius: 7px;
        background: #0dce9e;
        border: 1px solid #0dce9e;
      }
    }
  }
  .footer-nav {
    display: flex;
    justify-content: space-between;
    // white-space: nowrap;
    a {
      transition: color 0.3s;
      cursor: url("@/assets/mouse/x2.cur"), auto !important;
      &:hover {
        color: var(--a-button-hover-color);
      }
    }
    .records {
      margin-right: 30px;
      height: 60px;
      line-height: 60px;
    }
    .footer-nav-start {
      display: flex;
      .footer_nav_start_item {
        margin-right: 16px;
        height: 60px;
        line-height: 60px;
        .footer_item {
          transition: color 0.3s;
          cursor: url("@/assets/mouse/x2.cur"), auto !important;
          &:hover {
            color: var(--a-button-hover-color);
          }
        }
      }
    }
    .footer-nav-end {
      height: 60px;
      line-height: 60px;
    }
  }
}
</style>